var c = require('../lib/common.js');
var cf = require('../lib/config.js')
Page({

  /**
   * 页面的初始数据
   */
  data: {
    page: 0
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    var status = options.status;
    var rid = wx.getStorageSync('userinfo').id;
    var page = this.data.page;
    var that=this;
    c.ajax(
      cf.hostapi + 'getriderAllOrderList', {
        rid: rid,
        page: page,
        status: status
      },
      res => {
        if (res.data.retcode == 200) {
          wx.hideLoading();
          var list = res.data.data;
        };
        setInterval(() => {
          for (var i = 0; i < list.length; i++) {
            var timestamp = Date.parse(new Date());
            if (list[i]['status'] == 3) {
              //还没有到过期时间
              if (list[i]['out_time'] >= parseInt(timestamp / 1000)) {
                console.log('out_time----' + list[i]['out_time'] + '---------' + parseInt(timestamp / 1000));
                var xiangjian = list[i]['out_time'] - parseInt(timestamp / 1000);
                var miao = (xiangjian % 60);
                var fenz = parseInt(xiangjian / 60);
                list[i]['daojishi'] = '倒计时：' + fenz + '分:' + miao + '秒';
                list[i]['guoqi'] = 0;
                that.setData({
                  list: list
                })
                //此订单已经过期
              } else {
                var xiangjian = parseInt(timestamp / 1000) - list[i]['out_time'];
                console.log(xiangjian);
                var hurs = parseInt(xiangjian / 3600);
                var hursm = (xiangjian % 3600);
                var fenz = parseInt(hursm / 60);
                var miam = (xiangjian % 60);
                list[i]['daojishi'] = '已过期:' + hurs + '时:' + fenz + '分:' + miam + '秒';
                list[i]['guoqi'] = 1;
                that.setData({
                  list: list
                })
              }
            }
          }
        }, 1000)
        that.setData({ list: list})
      }
    );
  },

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {

  },
  makecall:function(e){
    var phone=e.currentTarget.dataset.phone;
    wx.makePhoneCall({
      phoneNumber:phone
    })
  }
})